package com.spring.springboot.controller;

import com.spring.springboot.Mapper.UserMapper;
import com.spring.springboot.Service.UserListService;
import com.spring.springboot.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author lking
 * @date 2019/11/27 20:26
 **/

@Controller
public class MyBatisController {

    @Autowired
   UserListService userListService;

    @RequestMapping("/listUser")
    public String listStudent(Model model) {
        List<User> users = userListService.findAll();
        System.out.println(users.size());
        System.out.println(users.get(0).getId());
        model.addAttribute("users", users);
        return "listUser";
    }

    @RequestMapping("/addUser")
    public String addStudent(Model model) {
        User user = new User();
        user.setAge(21);
        user.setId(134);
        user.setName("坤");

        userListService.insertUser(user);
        List<User> users = userListService.findAll();
        System.out.println(users.size());
        System.out.println(users.get(0).getId());
        model.addAttribute("users", users);
        return "listUser";
    }

}


